/** 根据传入的函数进行筛选浅拷贝 */

const arr = [1, 2, 3];
console.log(
  arr.filter(
    function (item) {
      return item > this.num;
    },
    { num: 2 }
  )
);

function myFilter(fn, thisArg) {
  let result = [];
  for (let i = 0; i < this.length; i++) {
    if (fn.call(thisArg, this[i], i, this)) {
      result.push(this[i]);
    }
  }
  return result;
}

Array.prototype.myFilter = myFilter;

console.log(
  arr.myFilter(
    function (item) {
      return item > this.num;
    },
    { num: 2 }
  )
);
